﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using StuMngVan.Dals;
using StuMngVan.Entities;

namespace StuMngVan
{
    public partial class FormTeacher : Form
    {
        public FormTeacher()
        {
            InitializeComponent();
        }

        private void FormTeacher_Load(object sender, EventArgs e)
        {

        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            //string stxtName = txtName.Text;
            //List<Teacher> teachers = Dal4Teacher.SearchAllTeachers(stxtName);
            //gvTeachers.DataSource = teachers;

            ///【闻祖东 2013-4-2-221547】像这种本身一行代码并不多的，你可以一次性将三句代码写成一句。
            ///很多时候代码的简洁性尤其是在多人的项目里面相当重要。
            gvTeachers.DataSource = Dal4Teacher.SearchAllTeachers(txtName.Text);
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            FormAddTeacher formAddTeacher = new FormAddTeacher();
            formAddTeacher.ShowDialog();
            btnSearch.PerformClick();
        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
            Teacher tcherSelected = gvTeachers.SelectedRows[0].DataBoundItem as Teacher;
            Dal4Teacher.DeleteTeacher(tcherSelected);
            MessageBox.Show(string.Format("删除老师{0}成功", tcherSelected.Name));
            btnSearch.PerformClick();
        }
    }
}
